Add timeout for requests.#8
Conversation
There was a problem hiding this comment.
Thank you for your contribution! It's great to have people interested in this project.
I'm pushing this one back because it adds too many dependencies for something that can be accomplished without any. Check the Promise.race approach here: https://gist.github.com/davej/728b20518632d97eef1e5a13bf0d05c7
Simple enough. No need for more dependencies.
|
The solution by that link doesn't cancel the actual HTTP request sent. It just raises an error. That's where 'cancellable-fetch' lib comes into play. And 'promise-timeout' lib I've added actually uses Promise.race approach you mentioned. The only diff is it clears timeout if the request is successful or any other error happens. 'uuid' lib was needed for identifying the HTTP request to cancel although here I agree it can be just replaced by a simple counter. |
|
What you mention makes total sense. However, that would mean we should move away from the original implementation of the
I'm personally not interested in turning this into a fully-featured http library, there are great solutions out there making a great job at this. Let's keep the scope for now on being an abstraction of the |
Adds timeout support.
Important for production-ready apps.